// pages/inMap/inMap.js
const http = require('../../utils/HttpUtils.js');


const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gjz:'',
    show:false,
    sealist:[],
    list:[],
    input: '美食',
    latitude: 42.533922,
    longitude: 124.022227,
    satellite: false,
    age: 0,
    ages: 1,
    scale: 13,
    polygon: [{
      strokeColor:"#00000000",//线条的颜色
      strokeWidth: 1,//宽度
      fillColor:'#CCE7E790',
      zIndex:0,
      level:'aboveroads',
      points: [
        
      ]
    }
     
    ],
    markerId: 1,
   alllist:[],
    markers:[],
    markers1: [],
    markers2: [],
    markers3: [],
    content:''
  
  },
  mapClick(e) {
    // console.log(e);
   this.data.alllist.forEach(item=>{
     if (item.id == e.markerId) {
         this.data.content = item.content
         this.setData({
          content:JSON.parse(item.content) 
         })
     }
   })
    var id = e.markerId
    // console.log(id)
    this.setData({
      markerId: id
    })
    if (this.data.age == 0 || this.data.age == 2 || this.data.age == 3) {
      this.showModal();
    }
    if (this.data.age == 1) {
      // console.log(this.data.content);
      wx.navigateTo({
        url: '/pages/info/info?content='+encodeURIComponent(JSON.stringify(this.data.content))+'&id=12',
      })
    }

  },
  layer() {
    var lite = this.data.satellite
    if (lite == false) {
      this.setData({
        satellite: true
      })
    }
    if (lite == true) {
      this.setData({
        satellite: false
      })
    }
  },
  age1() {
    this.setData({
      show:false,
      age: 0,
      ages: 1,
      latitude: 42.533922,
      longitude: 124.022227,
      scale: 13
    })
  },
  age2() {

    this.setData({
      show:false,
      age: 1,
      ages: 1,
      latitude: 42.533922,
      longitude: 124.022227,
      scale: 11
    })
  },
  age3() {

    this.setData({
      show:false,
      age: 2,
      ages: 1,
      latitude: 42.708952,
      longitude: 124.178422,
      scale: 9
    })
  },
  age4() {

    this.setData({
      show:false,
      age: 3,
      ages: 1,
      latitude: 42.52678,
      longitude: 124.021524,
      scale: 12.5
    })
  },
  look(e){
    var src = e.currentTarget.dataset.src
    // console.log(src)
    wx.previewImage({
      current: src,
      urls:[src]
    })
  },
  gps() {
    this.setData({
      latitude: this.data.latitude + 0.00001,
      longitude: this.data.longitude + 0.00001
    })
    // console.log(this.data.latitude)
    // console.log(this.data.longitude)
  },
  clickme: function () {
    this.showModal();
  },
  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  clean(){
    this.setData({
      sealist:[]
    })
    // this.age1()
  },
  showsearch(){
    this.setData({
      show:!this.data.show
    })
  },
search(e){

  this.setData({
    gjz:e.detail.value
  })
  this.data.sealist =  this.data.markers.filter(item=>{
    if(item.title.indexOf(e.detail.value)!=-1){
      return item
    }
  })
  this.setData({
    sealist:this.data.sealist
  })
  // console.log(this.data.sealist)

},
go(e){
 this.clean()
  this.setData({
  
    show:false,
    age: 0,
    ages: 1,
    latitude: e.currentTarget.dataset.latitude,
    longitude: e.currentTarget.dataset.longitude,
    scale: 15.5
  })
},

 

  getlist(){
let that = this
wx.request({
  url: http.URL_SCENEINVEST+'?openId=' +app.globalData.openId,
  method:'POST',
  success:(res)=>{
    // console.log(res.data.page);
    let list = []
    for (var item in res.data.page) {
      list = list.concat(res.data.page[item])
      // console.log('11', item, res.data.page[item])
    }
  
    
    // console.log(list)
    
    that.setData({
     list:Object.keys(res.data.page)
    })
    for(let i = 0 ;i<list.length;i++){
        if (list[i].type=='龙头企业') {
          that.data.markers.push({
            id: Number(list[i].id),
         
            width: '70rpx',
            height: '70rpx',
            latitude: list[i].latitude,
            longitude: list[i].longitude,
            zIndex: 2,
            alpha: 0,
            title:  list[i].name,
            label: {
              content: list[i].name,
              fontSize: 12,
              padding: 8,
              textAlign: 'center',
              borderWidth: 2,
              borderColor: '#fff',
              display: 'ALWAYS',
              bgColor: list[i].color,
              color: '#fff'
            }
          })
        }

        if (list[i].type=='五大产业链群') {
          that.data.markers1.push({
            id: Number(list[i].id),
            // iconPath: '/img/地点.png',
            width: '70rpx',
            height: '70rpx',
            latitude: list[i].latitude,
            longitude: list[i].longitude,
            zIndex: 2,
            alpha: 0,
            title:  list[i].name,
            label: {
              content: list[i].name,
              fontSize: 12,
              padding: 8,
              textAlign: 'center',
             
              borderRadius:'6px',
              display: 'ALWAYS',
              bgColor: list[i].color,
              color: '#fff'
            }
          })
        }

        if (list[i].type=='七大国家地理标志认证产品') {
        
          that.data.markers2.push({


            id: Number(list[i].id) ,
            iconPath:list[i].icon,
           
            width: '70rpx',
            height: '70rpx',
            latitude: list[i].latitude,
            longitude: list[i].longitude,
            zIndex: 2,
           
            title:  list[i].name,
            label: {
              content:  list[i].name,
              padding: 10,
              borderRadius: 6,
              display: 'ALWAYS',
              anchorX: 15,
              anchorY: -37,
              color: '#fff',
              borderRadius: 6,
             
              bgColor:  list[i].color,
            }
          })
        }

        if (list[i].type=='闲置空间') {
          that.data.markers3.push({
            id: Number(list[i].id),
            // iconPath: '/img/地点.png',
            width: '70rpx',
            height: '70rpx',
            latitude: list[i].latitude,
            longitude: list[i].longitude,
            zIndex: 2,
            alpha: 0,
            title:  list[i].name,
            label: {
              content: list[i].name,
              fontSize: 12,
              padding: 8,
              textAlign: 'center',
              borderWidth: 2,
             borderColor: '#fff',
              display: 'ALWAYS',
              bgColor: list[i].color,
              color: '#fff'
            }
          })
        }
        that.setData({
          alllist:list,
          markers:that.data.markers,
          markers1:that.data.markers1,
          markers2:that.data.markers2,
          markers3:that.data.markers3,
        })

    }
  }
})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
this.getlist()


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
   onShareAppMessage(){
    return app.globalData.globalShareInfo
  }
})